#tag Class
Class NSArray
Inherits NSObject
	#tag Method, Flags = &h1000
		Function ArrayByAddingObject(anObject as NSObject) As NSArray
		  
		  #if targetMacOS
		    declare function arrayByAddingObject lib CocoaLib selector "arrayByAddingObject:" (obj_id as Ptr, anObject as Ptr) as Ptr
		    
		    dim anObjectRef as Ptr
		    if anObject <> nil then
		      anObjectRef = anObject
		    end if
		    
		    dim arrayRef as Ptr = arrayByAddingObject(self, anObjectRef)
		    
		    if arrayRef <> nil then
		      return new NSArray(arrayRef)
		    end if
		    
		  #else
		    #pragma unused anObject
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function ArrayByAddingObjectsFromArray(otherArray as NSArray) As NSArray
		  
		  #if targetMacOS
		    declare function arrayByAddingObjectsFromArray lib CocoaLib selector "arrayByAddingObjectsFromArray:" (obj_id as Ptr, otherArray as Ptr) as Ptr
		    
		    dim otherArrayRef as Ptr
		    if otherArray <> nil then
		      otherArrayRef = otherArray
		    end if
		    
		    dim newArrayRef as Ptr = arrayByAddingObjectsFromArray(self, otherArrayRef)
		    
		    if newArrayRef <> nil then
		      return new NSArray(newArrayRef)
		    end if
		    
		  #else
		    #pragma unused otherArray
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h21
		Private Shared Function ClassRef() As Ptr
		  
		  static ref as Ptr = Cocoa.NSClassFromString("NSArray")
		  return ref
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Sub Constructor(file as FolderItem)
		  
		  #if targetMacOS
		    declare function initWithContentsOfFile lib CocoaLib selector "initWithContentsOfFile:" (obj_id as Ptr, aPath as CFStringRef) as Ptr
		    
		    if file <> nil then
		      super.Constructor(initWithContentsOfFile(Allocate("NSArray"), file.POSIXPath), NSArray.hasOwnership)
		    end if
		    
		  #else
		    #pragma unused file
		  #endif
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1000
		Sub Constructor(anArray as NSArray)
		  
		  #if targetMacOS
		    declare function initWithArray lib CocoaLib selector "initWithArray:" (obj_id as Ptr, anArray as Ptr) as Ptr
		    
		    dim anArrayRef as Ptr
		    if anArray <> nil then
		      anArrayRef = anArray
		    end if
		    
		    super.Constructor(initWithArray(Allocate("NSArray"), anArrayRef), NSArray.hasOwnership)
		    
		  #else
		    #pragma unused anArray
		  #endif
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1000
		Sub Constructor(anArray as NSArray, copyItems as Boolean)
		  
		  #if targetMacOS
		    declare function initWithArray lib CocoaLib selector "initWithArray:copyItems:" (obj_id as Ptr, anArray as Ptr, flag as Boolean) as Ptr
		    
		    dim anArrayRef as Ptr
		    if anArray <> nil then
		      anArrayRef = anArray
		    end if
		    
		    super.Constructor(initWithArray(Allocate("NSArray"), anArrayRef, copyItems), NSArray.hasOwnership)
		    
		  #else
		    #pragma unused anArray
		    #pragma unused copyItems
		  #endif
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1000
		Sub Constructor(objects() as NSObject)
		  
		  #if targetMacOS
		    declare function initWithObjects lib CocoaLib selector "initWithObjects:count:" (obj_id as Ptr, objects as Ptr, count as UInt32) as Ptr
		    
		    const sizeOfPtr = 4
		    
		    dim uboundObject as UInt32 = objects.ubound
		    dim objectCount as UInt32 = uboundObject+1
		    if uboundObject > -1 then
		      
		      dim m as new MemoryBlock(sizeOfPtr*(objectCount))
		      for i as integer = 0 to uboundObject
		        m.UInt32Value(i*sizeOfPtr) = UInt32(objects(i).id)
		      next
		      
		      super.Constructor(initWithObjects(Allocate("NSArray"), m, objectCount), NSArray.hasOwnership)
		    end if
		    
		  #else
		    #pragma unused objects
		  #endif
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1000
		Sub Constructor(aURL as NSURL)
		  
		  #if targetMacOS
		    declare function initWithContentsOfURL lib CocoaLib selector "initWithContentsOfURL:" (obj_id as Ptr, aURL as Ptr) as Ptr
		    
		    dim urlRef as Ptr
		    if aURL <> nil then
		      urlRef = aURL
		    end if
		    
		    super.Constructor(initWithContentsOfURL(Allocate("NSArray"), urlRef), NSArray.hasOwnership)
		    
		  #else
		    #pragma unused aURL
		  #endif
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1000
		Sub Constructor(strings() as String)
		  
		  dim nsstr() as NSObject
		  for each str as String in strings
		    nsstr.Append new NSString(str)
		  next
		  
		  self.Constructor(nsstr)
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function ContainsObject(anObject as NSObject) As Boolean
		  
		  #if targetMacOS
		    declare function containsObject lib CocoaLib selector "containsObject:" (obj_id as Ptr, anObjects as Ptr) as Boolean
		    
		    dim anObjectRef as Ptr
		    if anObject <> nil then
		      anObjectRef = anObject
		    end if
		    
		    return containsObject(self, anObjectRef)
		    
		  #else
		    #pragma unused anObject
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function Copy() As NSArray
		  
		  #if TargetMacOS
		    declare function copy_ lib CocoaLib selector "copy" (obj_id as Ptr) as Ptr
		    
		    dim arrayRef as Ptr = copy_(self)
		    if arrayRef <> nil then
		      return new NSArray(arrayRef)
		    end if
		    
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Count() As UInt32
		  
		  #if targetMacOS
		    declare function count lib CocoaLib selector "count" (obj_id as Ptr) as UInt32
		    
		    return count(self)
		    
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		 Shared Function Create() As NSArray
		  
		  #if TargetMacOS
		    declare function array_ lib CocoaLib selector "array" (class_id as Ptr) as Ptr
		    
		    dim arrayRef as Ptr = array_(ClassRef)
		    if arrayRef <> nil then
		      return new NSArray(arrayRef)
		    end if
		    
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		 Shared Function CreateFromRSObjectsArray(theArray as variant) As NSArray
		  dim nsma as NSMutableArray = NSMutableArray.Create
		  
		  select case theArray.ArrayElementType
		  case Variant.TypeBoolean
		    dim arb() as Boolean = theArray
		    for each b as Boolean in arb
		      nsma.Append   new NSNumber( b )
		    next
		    
		  case Variant.TypeInteger
		    dim ari() as Integer = theArray
		    for each i as integer in ari
		      nsma.Append   new NSNumber( i )
		    next
		    
		  case Variant.TypeString
		    dim ars() as string = theArray
		    for each s as String in ars
		      nsma.Append   new NSString( s )
		    next
		    
		  case Variant.TypeDouble, Variant.TypeSingle
		    dim ard() as double = theArray
		    for each d as double in ard
		      nsma.Append   new NSNumber( d )
		    next
		    
		  case Variant.TypeDate
		    dim ardate() as Date = theArray
		    for each dd as date in ardate
		      nsma.Append   NSDate( dd )
		    next
		    
		  case 9
		    dim arv() as variant = theArray
		    for each v as variant in arv
		      nsma.Append   NSArray.CreateFromRSObjectsArray( v )
		    next
		  end select
		  
		  return  nsma.Copy
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		 Shared Function CreateWithArray(anArray as NSArray) As NSArray
		  
		  #if TargetMacOS
		    declare function arrayWithArray lib CocoaLib selector "arrayWithArray:" (class_id as Ptr, anArray as Ptr) as Ptr
		    
		    dim anArrayRef as Ptr
		    if anArray <> nil then
		      anArrayRef = anArray
		    end if
		    
		    dim arrayRef as Ptr = arrayWithArray(ClassRef, anArrayRef)
		    
		    if arrayRef <> nil then
		      return new NSArray(arrayRef)
		    end if
		    
		  #else
		    #pragma unused anArray
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		 Shared Function CreateWithFile(file as FolderItem) As NSArray
		  
		  #if TargetMacOS
		    declare function arrayWithContentsOfFile lib CocoaLib selector "arrayWithContentsOfFile:" (class_id as Ptr, aPath as CFStringRef) as Ptr
		    
		    if file <> nil then
		      dim arrayRef as Ptr = arrayWithContentsOfFile(ClassRef, file.POSIXPath)
		      
		      if arrayRef <> nil then
		        return new NSArray(arrayRef)
		      end if
		    end if
		    
		  #else
		    #pragma unused file
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		 Shared Function CreateWithObject(anObject as NSObject) As NSArray
		  
		  #if TargetMacOS
		    declare function arrayWithObject lib CocoaLib selector "arrayWithObject:" (class_id as Ptr, anObject as Ptr) as Ptr
		    
		    if anObject <> nil then
		      dim arrayRef as Ptr = arrayWithObject(ClassRef, anObject)
		      
		      if arrayRef <> nil then
		        return new NSArray(arrayRef)
		      end if
		    end if
		    
		  #else
		    #pragma unused anObject
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		 Shared Function CreateWithObjects(objects() as NSObject) As NSArray
		  
		  #if TargetMacOS
		    declare function arrayWithObjects lib CocoaLib selector "arrayWithObjects:count:" (class_id as Ptr, objects as Ptr, count as UInt32) as Ptr
		    
		    const sizeOfPtr = 4
		    
		    dim uboundObject as UInt32 = objects.ubound
		    dim objectCount as UInt32 = uboundObject+1
		    if uboundObject > -1 then
		      
		      dim m as new MemoryBlock(sizeOfPtr*(objectCount))
		      for i as integer = 0 to uboundObject
		        m.UInt32Value(i*sizeOfPtr) = UInt32(objects(i).id)
		      next
		      
		      dim arrayRef as Ptr = arrayWithObjects(ClassRef, m, objectCount)
		      
		      if arrayRef <> nil then
		        return new NSArray(arrayRef)
		      end if
		    end if
		    
		  #else
		    #pragma unused objects
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		 Shared Function CreateWithURL(aURL as NSURL) As NSArray
		  
		  #if TargetMacOS
		    declare function arrayWithContentsOfURL lib CocoaLib selector "arrayWithContentsOfURL:" (class_id as Ptr, aURL as Ptr) as Ptr
		    
		    if aURL <> nil then
		      dim arrayRef as Ptr = arrayWithContentsOfURL(ClassRef, aURL)
		      
		      if arrayRef <> nil then
		        return new NSArray(arrayRef)
		      end if
		    end if
		    
		  #else
		    #pragma unused aURL
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Enumerator() As NSEnumerator
		  
		  #if targetMacOS
		    declare function objectEnumerator lib CocoaLib selector "objectEnumerator" (obj_id as Ptr) as Ptr
		    
		    dim enumRef as Ptr = objectEnumerator(self)
		    
		    if enumRef <> nil then
		      return new NSEnumerator(enumRef)
		    end if
		    
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function IndexOf(anObject as NSObject) As UInt32
		  
		  #if targetMacOS
		    declare function indexOfObject lib CocoaLib selector "indexOfObject:" (obj_id as Ptr, anObject as Ptr) as UInt32
		    
		    dim anObjectRef as Ptr
		    if anObject <> nil then
		      anObjectRef = anObject
		    end if
		    
		    return indexOfObject(self, anObjectRef)
		    
		  #else
		    #pragma unused anObject
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function IndexOf(anObject as NSObject, range as Cocoa.NSRange) As UInt32
		  
		  #if targetMacOS
		    declare function indexOfObject lib CocoaLib selector "indexOfObject:inRange:" (obj_id as Ptr, anObject as Ptr, range as Cocoa.NSRange) as UInt32
		    
		    dim anObjectRef as Ptr
		    if anObject <> nil then
		      anObjectRef = anObject
		    end if
		    
		    return indexOfObject(self, anObjectRef, range)
		    
		  #else
		    #pragma unused anObject
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function IndexOfObjectIdentical(anObject as NSObject) As UInt32
		  
		  #if targetMacOS
		    declare function indexOfObjectIdenticalTo lib CocoaLib selector "indexOfObjectIdenticalTo:" (obj_id as Ptr, anObject as Ptr) as UInt32
		    
		    dim anObjectRef as Ptr
		    if anObject <> nil then
		      anObjectRef = anObject
		    end if
		    
		    return indexOfObjectIdenticalTo(self, anObjectRef)
		    
		  #else
		    #pragma unused anObject
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function IndexOfObjectIdentical(anObject as NSObject, range as Cocoa.NSRange) As UInt32
		  
		  #if targetMacOS
		    declare function indexOfObjectIdenticalTo lib CocoaLib selector "indexOfObjectIdenticalTo:inRange:" (obj_id as Ptr, anObject as Ptr, range as Cocoa.NSRange) as UInt32
		    
		    dim anObjectRef as Ptr
		    if anObject <> nil then
		      anObjectRef = anObject
		    end if
		    
		    return indexOfObjectIdenticalTo(self, anObjectRef, range)
		    
		  #else
		    #pragma unused anObject
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function IsEqual(otherArray as NSArray) As Boolean
		  
		  #if targetMacOS
		    declare function isEqualToArray lib CocoaLib selector "isEqualToArray:" (obj_id as Ptr, otherArray as Ptr) as Boolean
		    
		    dim arrayRef as Ptr
		    if otherArray <> nil then
		      arrayRef = otherArray
		    end if
		    
		    return isEqualToArray(self, arrayRef)
		    
		  #else
		    #pragma unused otherArray
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Join(separator as String) As String
		  
		  #if targetMacOS
		    declare function componentsJoinedByString lib CocoaLib selector "componentsJoinedByString:" (obj_id as Ptr, separator as CFStringRef) as CFStringRef
		    
		    return componentsJoinedByString(self, separator)
		    
		  #else
		    #pragma unused separator
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function LastValue() As Ptr
		  
		  #if targetMacOS
		    declare function lastObject lib CocoaLib selector "lastObject" (obj_id as Ptr) as Ptr
		    
		    return lastObject(self)
		    
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function Operator_Convert() As NSObject()
		  
		  return self.Values(Cocoa.NSMakeRange(0, self.Count))
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function Operator_Convert() As String()
		  
		  dim retArray() as String
		  
		  const sizeOfPtr = 4
		  dim arrayRange as Cocoa.NSRange = Cocoa.NSMakeRange(0, self.Count)
		  dim m as MemoryBlock = self.ValuesArray(arrayRange)
		  dim n as UInt32 = arrayRange.length-1
		  for i as integer = 0 to n
		    retArray.append new NSString(Ptr(m.UInt32Value(i*sizeOfPtr)))
		  next
		  
		  return retArray
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub Operator_Convert(objects() as NSObject)
		  
		  self.Constructor(objects)
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function ReverseEnumerator() As NSEnumerator
		  
		  #if targetMacOS
		    declare function reverseObjectEnumerator lib CocoaLib selector "reverseObjectEnumerator" (obj_id as Ptr) as Ptr
		    
		    dim enumRef as Ptr = reverseObjectEnumerator(self)
		    
		    if enumRef <> nil then
		      return new NSEnumerator(enumRef)
		    end if
		    
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Subarray(aRange as Cocoa.NSRange) As NSArray
		  
		  #if targetMacOS
		    declare function subarrayWithRange lib CocoaLib selector "subarrayWithRange:" (obj_id as Ptr, aRange as Cocoa.NSRange) as Ptr
		    
		    dim newArrayRef as Ptr = subarrayWithRange(self, aRange)
		    
		    if newArrayRef <> nil then
		      return new NSArray(newArrayRef)
		    end if
		    
		  #else
		    #pragma unused aRange
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Value(index as UInt32) As NSObject
		  
		  #if targetMacOS
		    declare function objectAtIndex lib CocoaLib selector "objectAtIndex:" (obj_id as Ptr, index as UInt32) as Ptr
		    
		    dim objRef as Ptr = objectAtIndex(self, index)
		    
		    if objRef <> nil then
		      return new NSObject(objRef)
		    end if
		    
		  #else
		    #pragma unused index
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Values(aRange as Cocoa.NSRange) As NSObject()
		  
		  const sizeOfPtr = 4
		  
		  dim rb_array() as NSObject
		  
		  dim m as MemoryBlock = self.ValuesArray(aRange)
		  
		  dim n as UInt32 = aRange.length-1
		  for i as integer = 0 to n
		    rb_array.append new NSObject(Ptr(m.UInt32Value(i*sizeOfPtr)))
		  next
		  
		  return rb_array
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Values(indexes() as UInt32) As NSArray
		  
		  #if targetMacOS
		    declare function objectsAtIndexes lib CocoaLib selector "objectsAtIndexes:" (obj_id as Ptr, indexes as Ptr) as Ptr
		    
		    dim indexSet as new NSMutableIndexSet
		    for each index as UInt32 in indexes
		      indexSet.Add(index)
		    next
		    
		    dim arrayRef as Ptr = objectsAtIndexes(self, indexSet)
		    
		    if arrayRef <> nil then
		      return new NSArray(arrayRef)
		    end if
		    
		  #else
		    #pragma unused indexes
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function ValuesArray(aRange as Cocoa.NSRange) As MemoryBlock
		  
		  #if targetMacOS
		    declare sub getObjects lib CocoaLib selector "getObjects:range:" (obj_id as Ptr, aBuffer as Ptr, aRange as Cocoa.NSRange)
		    
		    const sizeOfPtr = 4
		    
		    dim m as new MemoryBlock(sizeOfPtr*aRange.length)
		    
		    getObjects self, m, aRange
		    
		    return m
		    
		  #else
		    #pragma unused aRange
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function VariantValue() As variant
		  
		  dim n as UInt32 = self.Count - 1
		  
		  dim result() as Variant
		  dim v as VariantValueInterface
		  
		  for i as Integer = 0 to n
		    v = VariantValueInterface(Cocoa.NSObjectFromNSPtr( value( i )))
		    result.Append v.VariantValue
		  next
		  
		  return result
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Write(file as FolderItem, atomically as Boolean) As Boolean
		  
		  #if targetMacOS
		    declare function writeToFile lib CocoaLib selector "writeToFile:atomically:" (obj_id as Ptr, path as CFStringRef, flag as Boolean) as Boolean
		    
		    if file <> nil then
		      return writeToFile(self, file.POSIXPath, atomically)
		    else
		      return false
		    end if
		    
		  #else
		    #pragma unused file
		    #pragma unused atomically
		  #endif
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h1000
		Function Write(aURL as NSURL, atomically as Boolean) As Boolean
		  
		  #if targetMacOS
		    declare function writeToURL lib CocoaLib selector "writeToURL:atomically:" (obj_id as Ptr, aURL as Ptr, flag as Boolean) as Boolean
		    
		    dim urlRef as Ptr
		    if urlRef <> nil then
		      urlRef = aURL
		    end if
		    
		    return writeToURL(self, urlRef, atomically)
		    
		  #else
		    #pragma unused aURL
		    #pragma unused atomically
		  #endif
		  
		End Function
	#tag EndMethod


	#tag ViewBehavior
		#tag ViewProperty
			Name="Description"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
			InheritedFrom="NSObject"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
